package com.jzoffer;

/*
*  题目 二维数组中的查找
* */
public class One {
    public static void main(String[] args) {
        int [][]array = new int[5][5];
        int target = 23468;
        int value = 1;
        for(int i = 0;i < 5;i++){
            for(int j = 0;j < 5;j++){
                array[i][j] = value;
                value++;
            }
        }

        One one = new One();
        System.out.println(one.find(target, array));

    }

    public boolean find(int target,int [][] array){

        if(array == null || array.length < 1 || array[0].length < 1){
            return false;
        }
        int row = array.length;
        int col = array[0].length;
        int r = 0;
        int c = col- 1;

        while (r < row && c >= 0){
            if(target == array[r][c]){
                return true;
            }else if(target > array[r][c]){
                r++;
            }else{
                c--;
            }
        }
        return false;
    }
}
